unit LogViewFormUnit;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, LResources, Forms, StdCtrls, ExtCtrls, Menus,
  Controls, ClipBrd, LogSystm, WrkspcCfgrtn;

type

  { TLogViewForm }

  TLogViewForm = class(TForm)
    LogList: TListBox;
    LogTimer: TTimer;
    miOnTop: TMenuItem;
    miClear: TMenuItem;
    miCopy: TMenuItem;
    miFreez: TMenuItem;
    mi1sec: TMenuItem;
    mi12sec: TMenuItem;
    mi2sec: TMenuItem;
    LogPopupMenu: TPopupMenu;
    procedure FormCreate(Sender: TObject);
    procedure LogTimerTimer(Sender: TObject);
    procedure miOnTopClick(Sender: TObject);
    procedure miClearClick(Sender: TObject);
    procedure miCopyClick(Sender: TObject);
    procedure miFreezClick(Sender: TObject);
  private
    { private declarations }
    iLog: TSystmLog;
    LastMSGid: TMsgID;
  public
    { public declarations }
  end;

var
  LogViewForm: TLogViewForm;

implementation

{ TLogViewForm }

procedure TLogViewForm.LogTimerTimer(Sender: TObject);
var
  i, j: integer;
begin
  if not assigned(iLog) then exit;
  i := LogList.Count;
  iLog.GetMessagesAfterID(LastMSGid,LogList.Items);
  j := LogList.Count;
  if (j > 3) and (j > i) then begin
    i := LogList.ItemHeight;
    if i > 0 then
      LogList.TopIndex := j - trunc(LogList.Height / i) + 1;
  end;
end;

procedure TLogViewForm.FormCreate(Sender: TObject);
begin
  LastMSGid := -1;
  iLog := IIntegralConfig.modLOG;
  LogTimer.Enabled := True;
end;

procedure TLogViewForm.miOnTopClick(Sender: TObject);
begin
  if miOnTop.Checked then FormStyle := fsStayOnTop else FormStyle := fsNormal;
end;

procedure TLogViewForm.miClearClick(Sender: TObject);
begin
  LogList.Clear;
end;

procedure TLogViewForm.miCopyClick(Sender: TObject);
begin
  Clipboard.SetTextBuf(LogList.Items.GetText);
end;

procedure TLogViewForm.miFreezClick(Sender: TObject);
begin
  LogTimer.Enabled := not miFreez.Checked;
  LogTimer.Interval := TMenuItem(Sender).Tag;
end;

initialization
  {$I logviewformunit.lrs}

end.

